package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain; // 添加这行关键导入

@Configuration
@EnableWebSecurity
public class WebSecurityConfig {

    // 注意返回类型和导入的匹配
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .csrf(csrf -> csrf.disable())
                .authorizeHttpRequests(auth -> auth
                        .requestMatchers("/api/users/**").permitAll()
                        .anyRequest().authenticated()
                );
        return http.build(); // 这里返回的DefaultSecurityFilterChain是SecurityFilterChain的实现类
    }
}